package com.yuyue.note01.config;

import com.yuyue.note02.controller.interceptor.ProjectInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * SpringMVC配置类
 */
//创建配置文件，用于加载 Controller
@Configuration
//@ComponentScan({"com.yuyue.*.controller", "com.yuyue.*.config"})
@ComponentScan("com.yuyue.*.controller")
//开启自动转换json数据的支持
//该注解整合了多个功能，此处仅使用其中一部分功能，即json数据进行自动类型转换
@EnableWebMvc
public class SpringMVCConfig implements WebMvcConfigurer {
    @Autowired
    //自动填充拦截器
    private ProjectInterceptor projectInterceptor;

    @Override
    //添加拦截器
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(projectInterceptor);
    }
}
